#include "tcpcline.h"
#include <stdio.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <string.h>
#include <unistd.h>

int init_tcp(char * ip,int port)
{
	int fd;
	fd = socket(AF_INET,SOCK_STREAM,0);
	if(fd<0) 
	{
		printf("tcp初始化失败\r\n");
		return -1;
	}
	struct sockaddr_in saddr;
	saddr.sin_family = AF_INET;
	saddr.sin_port = htons(port);
	saddr.sin_addr.s_addr = inet_addr(ip);
	int ret = bind(fd,(struct sockaddr*)&saddr,sizeof(saddr));
	if(ret<0)
	{
		printf("bind fail\r\n");
		return -2;
	}
	listen(fd,5);
	return fd;
}




